package helloworld.admin.service.news;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import helloworld.admin.bean.NewsAdminBean;
import helloworld.dao.NewsDao;
import helloworld.dao.DAOException;
import helloworld.dao.DAOFactory;
import helloworld.example.exception.ErrorLevel;

/**
 * NewsListService provides the Service of Listing Newss.
 * It is also an example of Session Facade pattern.
 * In real projects, NewsListService is implemented as Stateful Session EJB.
 * 
 * But this is kept seperate from the NewsControllerService
 * The reason is that this Service uses ValueListHandler  (Another Core J2EE Pattern) 
 * to access the DAO and is of more stateful nature.
 * Seperating will prevent mingling of this stateful session faceade with 
 * otherwise stateless nature of NewsControllerService
 * 
 * @author TUYEN-DM
 * @version $Revision:   $ $Date: 2009/05/25  $
 */
public class NewsListService 
{

	public NewsAdminBean[] findNews(String newsName) throws NewsListServiceException
	{
		NewsAdminBean[] newss = null;
		try
		{
			DAOFactory daoFactory = DAOFactory.getDAOFactory(DAOFactory.MS_ACCESS);
			NewsDao dao = daoFactory.getNewsDAO();
			newss = dao.find(newsName);
		}
		catch (DAOException de)
		{
			if (! de.isLogged())
			{
				Log log = LogFactory.getLog("NewsListService");
				de.log(log);
			}
			throw new NewsListServiceException(de.getUserMessageKey(), 
									de.getValueReplacementArray(),
									de.getUniqueID(), 
									ErrorLevel.ERROR);
		}
		
		return newss;
	}

}